﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Caliburn.PresentationFramework.ApplicationModel;
using Caliburn.PresentationFramework.Metadata;
using System.Windows;

namespace PCUserTimer.ViewModels
{
    public class MainViewModel : PresenterManager
    {
        readonly Func<int, WorkViewModel> Work;
        readonly Func<int, BreakViewModel> Break;

        public MainViewModel(Func<int, WorkViewModel> work, Func<int, BreakViewModel> @break)
        {
            Work = work;
            Break = @break;

            activityEnumerator = Activity.GetEnumerator();
            NextActivity();
        }

        IEnumerable<ActivityViewModelBase> ActivityBlock
        {
            get
            {
                yield return Work(25);
                yield return Break(5);
                yield return Work(25);
                yield return Break(5);
                yield return Work(25);
                yield return Break(15);
            }
        }

        IEnumerable<ActivityViewModelBase> Activity { get { return ActivityBlock.Repeat(); } }

        IEnumerator<ActivityViewModelBase> activityEnumerator;

        void NextActivity()
        {
            activityEnumerator.MoveNext();
            var current = activityEnumerator.Current;

            ShowActivity(current);
        }

        private void ShowActivity(ActivityViewModelBase activity)
        {
            activity.Finished += delegate { NextActivity(); };

            Open(activity, _ => { });
        }
    }
}
